<?php
/* ******************************
	schedule aJax actions
   ******************************
*/
	include('../../includes/classes/core.php');
	$action 	= $_REQUEST['act'];
	$start		= $_REQUEST['start'];
    $end		= $_REQUEST['end'];
    $oid		= $_REQUEST['oid'];
    
    $error	= '';
    $data	= '';
	
	switch ($action) {
	    case 'get_list':
    	    $count = $_REQUEST['count'];
    	    
    	    $rResult = mysql_query("SELECT   	pos_money_action.id,
												pos_money_action.date,
												persons.`name`,
												IF(pos_money_action.action = 1, 'შემოსავალი', 'გასავალი') AS `action`,
    	    									IF(pos_money_action.action = 2, CONCAT('-',pos_money_action.money), pos_money_action.money) AS `money`
									FROM		pos_money_action
									LEFT JOIN	persons ON pos_money_action.user_id = persons.user_id
									WHERE     	DATE(pos_money_action.date)  BETWEEN  date('$start')  AND date('$end') AND pos_money_action.pos_id = $oid
									");
			
			$data = array(
				"aaData"	=> array()
			);
			
			while ( $aRow = mysql_fetch_array( $rResult ) )
			{
				$row = array();
				for ( $i = 0 ; $i < $count ; $i++ )
				{
					/* General output */
					$row[] = $aRow[$i];
				}
				$data['aaData'][] = $row;
			}

	        break;	  
        case 'select_pos':
        	$data	= array('page' => SelectPOS());
        
        	break;
	    default:
	       	echo "null";
	}
	
	$data['error'] = $error;
	
	echo json_encode($data);
	
	function SelectPOS()
	{
		$data = '
		<div id="dialog-form">
		    <fieldset>
		    	<table class="dialog-form-table">
					<tr>
						<td style="width: 170px;"><label for="obj_id">აირჩიეთ სალარო</label></td>
						<td>
							<select id="obj_id" class="idls">' . GetObjectList() . '</select>
						</td>
					</tr>
				</table>
	        </fieldset>
	    </div>';
		return $data;
	}
	
	function GetObjectList()
	{
		$data = '';
		$req = mysql_query("SELECT 	`id`, 
									`name`
							FROM 	`object`
							WHERE 	`type` = 5 AND `actived`=1");
	
		while( $res = mysql_fetch_assoc($req)){
			$data .= '<option value="' . $res['id'] . '">' . $res['name'] . '</option>';
		}
	
		return $data;
	}
?>